
/*
 * formvalidation_core.js
 */

var el;

(function($) {

module("formvalidation");

test("no rules", function() {

	expect(4);

	ok($.formvalidation('').valid, "[string] '' is valid");
	ok($('<input type="text" value="" />').formvalidation().formvalidation('isvalid'), "[input] '' is valid");
	ok($.formvalidation('test').valid, "[string] 'text' is valid");
	ok($('<input type="text" value="test" />').formvalidation().formvalidation('isvalid'), "[input] 'text' is valid");

});

test("required", function() {

	expect(6);

	ok($.formvalidation('test', {required: true}).valid, "[string] 'test' is valid");
	ok($('<input type="text" value="test" />').formvalidation({rules:{required:true}}).formvalidation('isvalid'), "[input:options] 'test' is valid");
	ok($('<input type="text" value="test" required="required" />').formvalidation().formvalidation('isvalid'), "[input:attribute] 'test' is valid");
	ok(!$.formvalidation('', {required: true}).valid, "[string] '' is not valid");
	ok(!$('<input type="text" value="" />').formvalidation({rules:{required:true}}).formvalidation('isvalid'), "[input:options] '' is not valid");
	ok(!$('<input type="text" value="" required="required" />').formvalidation().formvalidation('isvalid'), "[input:attribute] '' is not valid");

});

test("email", function() {

	expect(9);

	ok(!$.formvalidation('test', {email: true}).valid, "[string] 'test' is not valid");
	ok(!$('<input type="text" value="test" />').formvalidation({rules:{email:true}}).formvalidation('isvalid'), "[input:options] 'test' is not valid");
	ok(!$('<input type="email" value="test" />').formvalidation().formvalidation('isvalid'), "[input:attribute] 'test' is not valid");
	ok($.formvalidation('', {email: true}).valid, "[string] '' is valid");
	ok($('<input type="text" value="" />').formvalidation({rules:{email:true}}).formvalidation('isvalid'), "[input:options] '' is valid");
	ok($('<input type="email" value="" />').formvalidation().formvalidation('isvalid'), "[input:attribute] '' is valid");
	ok($.formvalidation('tester@example.com', {email: true}).valid, "[string] '' is valid");
	ok($('<input type="text" value="tester@example.com" />').formvalidation({rules:{email:true}}).formvalidation('isvalid'), "[input:options] '' is valid");
	ok($('<input type="email" value="tester@example.com" />').formvalidation().formvalidation('isvalid'), "[input:attribute] '' is valid");

});

test("url", function() {

	expect(9);

	ok(!$.formvalidation('test', {url: true}).valid, "[string] 'test' is not valid");
	ok(!$('<input type="text" value="test" />').formvalidation({rules:{url:true}}).formvalidation('isvalid'), "[input:options] 'test' is not valid");
	ok(!$('<input type="url" value="test" />').formvalidation().formvalidation('isvalid'), "[input:attribute] 'test' is not valid");
	ok($.formvalidation('', {url: true}).valid, "[string] '' is valid");
	ok($('<input type="text" value="" />').formvalidation({rules:{url:true}}).formvalidation('isvalid'), "[input:options] '' is valid");
	ok($('<input type="url" value="" />').formvalidation().formvalidation('isvalid'), "[input:attribute] '' is valid");
	ok($.formvalidation('http://www.example.com', {url: true}).valid, "[string] '' is valid");
	ok($('<input type="text" value="http://www.example.com" />').formvalidation({rules:{url:true}}).formvalidation('isvalid'), "[input:options] '' is valid");
	ok($('<input type="url" value="http://www.example.com" />').formvalidation().formvalidation('isvalid'), "[input:attribute] '' is valid");

});

test("date", function() {

	expect(9);
	
	var now = new Date();
	var today = now.getDate() + '/' + now.getMonth() + '/' + now.getFullYear();

	ok(!$.formvalidation('test', {date: true}).valid, "[string] 'test' is not valid");
	ok(!$('<input type="text" value="test" />').formvalidation({rules:{date:true}}).formvalidation('isvalid'), "[input:options] 'test' is not valid");
	ok(!$('<input type="date" value="test" />').formvalidation().formvalidation('isvalid'), "[input:attribute] 'test' is not valid");
	ok($.formvalidation('', {date: true}).valid, "[string] '' is valid");
	ok($('<input type="text" value="" />').formvalidation({rules:{date:true}}).formvalidation('isvalid'), "[input:options] '' is valid");
	ok($('<input type="date" value="" />').formvalidation().formvalidation('isvalid'), "[input:attribute] '' is valid");
	ok($.formvalidation(today, {date: true}).valid, "[string] '' is valid");
	ok($('<input type="text" value="'+ today +'" />').formvalidation({rules:{date:true}}).formvalidation('isvalid'), "[input:options] '' is valid");
	ok($('<input type="date" value="'+ today +'" />').formvalidation().formvalidation('isvalid'), "[input:attribute] '' is valid");

});

test("number", function() {

	expect(12);

	ok(!$.formvalidation('test', {number: true}).valid, "[string] 'test' is not valid");
	ok(!$('<input type="text" value="test" />').formvalidation({rules:{number:true}}).formvalidation('isvalid'), "[input:options] 'test' is not valid");
	ok(!$('<input type="number" value="test" />').formvalidation().formvalidation('isvalid'), "[input:attribute] 'test' is not valid");
	ok($.formvalidation('', {number: true}).valid, "[string] '' is valid");
	ok($('<input type="text" value="" />').formvalidation({rules:{number:true}}).formvalidation('isvalid'), "[input:options] '' is valid");
	ok($('<input type="number" value="" />').formvalidation().formvalidation('isvalid'), "[input:attribute] '' is valid");
	ok($.formvalidation(999, {number: true}).valid, "[string] '' is valid");
	ok($('<input type="text" value="999" />').formvalidation({rules:{number:true}}).formvalidation('isvalid'), "[input:options] '' is valid");
	ok($('<input type="number" value="999" />').formvalidation().formvalidation('isvalid'), "[input:attribute] '' is valid");
	ok(!$.formvalidation('9.9.9', {number: true}).valid, "[string] '9.9.9' is not valid");
	ok(!$('<input type="text" value="9.9.9" />').formvalidation({rules:{number:true}}).formvalidation('isvalid'), "[input:options] '9.9.9' is not valid");
	ok(!$('<input type="number" value="9.9.9" />').formvalidation().formvalidation('isvalid'), "[input:attribute] '9.9.9' is not valid");

});

test("min", function() {

	expect(15);

	ok(!$.formvalidation('1', {min: 10}).valid, "[string] '1' is not valid");
	ok(!$('<input type="text" value="1" />').formvalidation({rules:{min: 10}}).formvalidation('isvalid'), "[input:options] '1' is not valid");
	ok(!$('<input type="number" value="1" min="10" />').formvalidation().formvalidation('isvalid'), "[input:attribute] '1' is not valid");
	ok(!$.formvalidation('', {min: 10}).valid, "[string] '' is not valid");
	ok(!$('<input type="text" value="" />').formvalidation({rules:{min: 10}}).formvalidation('isvalid'), "[input:options] '' is not valid");
	ok(!$('<input type="number" value="" min="10" />').formvalidation().formvalidation('isvalid'), "[input:attribute] '' is not valid");
	ok($.formvalidation(999, {min: 10}).valid, "[string] '999' is valid");
	ok($('<input type="text" value="999" />').formvalidation({rules:{min: 10}}).formvalidation('isvalid'), "[input:options] '999' is valid");
	ok($('<input type="number" value="999" min="10" />').formvalidation().formvalidation('isvalid'), "[input:attribute] '999' is valid");
	ok($.formvalidation(10, {min: 10}).valid, "[string] '10' is valid");
	ok($('<input type="text" value="10" />').formvalidation({rules:{min: 10}}).formvalidation('isvalid'), "[input:options] '10' is valid");
	ok($('<input type="number" value="10" min="10" />').formvalidation().formvalidation('isvalid'), "[input:attribute] '10' is valid");
	ok(!$.formvalidation('1', {min: 10}).valid, "[string] '1' is not valid");
	ok(!$('<input type="text" value="1" />').formvalidation({rules:{min: 10}}).formvalidation('isvalid'), "[input:options] '1' is not valid");
	ok(!$('<input type="number" value="1" min="10" />').formvalidation().formvalidation('isvalid'), "[input:attribute] '1' is not valid");

});

test("max", function() {

	expect(15);

	ok(!$.formvalidation('15', {max: 10}).valid, "[string] '15' is not valid");
	ok(!$('<input type="text" value="15" />').formvalidation({rules:{max: 10}}).formvalidation('isvalid'), "[input:options] '15' is not valid");
	ok(!$('<input type="number" value="15" max="10" />').formvalidation().formvalidation('isvalid'), "[input:attribute] '15' is not valid");
	ok($.formvalidation('', {max: 10}).valid, "[string] '' is valid");
	ok($('<input type="text" value="" />').formvalidation({rules:{max: 10}}).formvalidation('isvalid'), "[input:options] '' is valid");
	ok($('<input type="number" value="" max="10" />').formvalidation().formvalidation('isvalid'), "[input:attribute] '' is valid");
	ok($.formvalidation(1, {max: 10}).valid, "[string] '1' is valid");
	ok($('<input type="text" value="1" />').formvalidation({rules:{max: 10}}).formvalidation('isvalid'), "[input:options] '1' is valid");
	ok($('<input type="number" value="1" max="10" />').formvalidation().formvalidation('isvalid'), "[input:attribute] '1' is valid");
	ok($.formvalidation(10, {max: 10}).valid, "[string] '10' is valid");
	ok($('<input type="text" value="10" />').formvalidation({rules:{max: 10}}).formvalidation('isvalid'), "[input:options] '10' is valid");
	ok($('<input type="number" value="10" max="10" />').formvalidation().formvalidation('isvalid'), "[input:attribute] '10' is valid");
	ok(!$.formvalidation('999', {max: 10}).valid, "[string] '999' is not valid");
	ok(!$('<input type="text" value="999" />').formvalidation({rules:{max: 10}}).formvalidation('isvalid'), "[input:options] '999' is not valid");
	ok(!$('<input type="number" value="999" max="10" />').formvalidation().formvalidation('isvalid'), "[input:attribute] '999' is not valid");

});

test("maxlength", function() {

	expect(12);

	ok(!$.formvalidation('longer than 10', {maxlength: 10}).valid, "[string] 'longer than 10' is not valid");
	ok(!$('<input type="text" value="longer than 10" />').formvalidation({rules:{maxlength: 10}}).formvalidation('isvalid'), "[input:options] 'longer than 10' is not valid");
	ok(!$('<input type="text" value="longer than 10" maxlength="10" />').formvalidation().formvalidation('isvalid'), "[input:attribute] 'longer than 10' is not valid");
	ok($.formvalidation('', {maxlength: 10}).valid, "[string] '' is valid");
	ok($('<input type="text" value="" />').formvalidation({rules:{maxlength: 10}}).formvalidation('isvalid'), "[input:options] '' is valid");
	ok($('<input type="text" value="" maxlength="10" />').formvalidation().formvalidation('isvalid'), "[input:attribute] '' is valid");
	ok($.formvalidation('under 10', {maxlength: 10}).valid, "[string] 'under 10' is valid");
	ok($('<input type="text" value="under 10" />').formvalidation({rules:{maxlength: 10}}).formvalidation('isvalid'), "[input:options] 'under 10' is valid");
	ok($('<input type="text" value="under 10" maxlength="10" />').formvalidation().formvalidation('isvalid'), "[input:attribute] 'under 10' is valid");
	ok($.formvalidation('ten letter', {maxlength: 10}).valid, "[string] 'ten letter' is valid");
	ok($('<input type="text" value="ten letter" />').formvalidation({rules:{maxlength: 10}}).formvalidation('isvalid'), "[input:options] 'ten letter' is valid");
	ok($('<input type="text" value="ten letter" maxlength="10" />').formvalidation().formvalidation('isvalid'), "[input:attribute] 'ten letter' is valid");

});

test("lessthan", function() {

	expect(12);
	
	$('#testinput').val(10);

	ok($.formvalidation($('#testinput').val()-1, {lessthan: 'testinput'}).valid, "[string] '#testinput-1' is valid");
	ok($('<input type="text" value="999" />').val($('#testinput').val()-1).formvalidation({rules:{lessthan: 'testinput'}}).formvalidation('isvalid'), "[input:options] '#testinput-1' is valid");
	ok($('<input type="text" value="999" lessthan="testinput" />').val($('#testinput').val()-1).formvalidation().formvalidation('isvalid'), "[input:attribute] '#testinput-1' is valid");
	ok(!$.formvalidation($('#testinput').val(), {lessthan: 'testinput'}).valid, "[string] '#testinput' is not valid");
	ok(!$('<input type="text" value="10" />').val($('#testinput').val()).formvalidation({rules:{lessthan: 'testinput'}}).formvalidation('isvalid'), "[input:options] '#testinput' is not valid");
	ok(!$('<input type="text" value="10" lessthan="testinput" />').val($('#testinput').val()).formvalidation().formvalidation('isvalid'), "[input:attribute] '#testinput' is not valid");
	ok(!$.formvalidation(10, {lessthan: 'testinput'}).valid, "[string] '10' is not valid");
	ok(!$('<input type="text" value="10" />').formvalidation({rules:{lessthan: 'testinput'}}).formvalidation('isvalid'), "[input:options] '10' is not valid");
	ok(!$('<input type="text" value="10" lessthan="testinput" />').formvalidation().formvalidation('isvalid'), "[input:attribute] '10' is not valid");
	ok($.formvalidation(1, {lessthan: 'testinput'}).valid, "[string] '1' is valid");
	ok($('<input type="text" value="1" />').formvalidation({rules:{lessthan: 'testinput'}}).formvalidation('isvalid'), "[input:options] '1' is valid");
	ok($('<input type="text" value="1" lessthan="testinput" />').formvalidation().formvalidation('isvalid'), "[input:attribute] '1' is valid");
	
});

test("morethan", function() {

	expect(12);
	
	$('#testinput').val(10);

	ok($.formvalidation($('#testinput').val()+1, {morethan: 'testinput'}).valid, "[string] '#testinput+1' is valid");
	ok($('<input type="text" value="1" />').val($('#testinput').val()+1).formvalidation({rules:{morethan: 'testinput'}}).formvalidation('isvalid'), "[input:options] '#testinput+1' is valid");
	ok($('<input type="text" value="1" morethan="testinput" />').val($('#testinput').val()+1).formvalidation().formvalidation('isvalid'), "[input:attribute] '#testinput+1' is valid");
	ok(!$.formvalidation($('#testinput').val(), {morethan: 'testinput'}).valid, "[string] '#testinput' is not valid");
	ok(!$('<input type="text" value="10" />').val($('#testinput').val()).formvalidation({rules:{morethan: 'testinput'}}).formvalidation('isvalid'), "[input:options] '#testinput' is not valid");
	ok(!$('<input type="text" value="10" morethan="testinput" />').val($('#testinput').val()).formvalidation().formvalidation('isvalid'), "[input:attribute] '#testinput' is not valid");
	ok(!$.formvalidation(1, {morethan: 'testinput'}).valid, "[string] '1' is not valid");
	ok(!$('<input type="text" value="1" />').formvalidation({rules:{morethan: 'testinput'}}).formvalidation('isvalid'), "[input:options] '1' is not valid");
	ok(!$('<input type="text" value="1" morethan="testinput" />').formvalidation().formvalidation('isvalid'), "[input:attribute] '1' is not valid");
	ok($.formvalidation(999, {morethan: 'testinput'}).valid, "[string] '999' is valid");
	ok($('<input type="text" value="999" />').formvalidation({rules:{morethan: 'testinput'}}).formvalidation('isvalid'), "[input:options] '999' is valid");
	ok($('<input type="text" value="999" morethan="testinput" />').formvalidation().formvalidation('isvalid'), "[input:attribute] '999' is valid");
	
});

test("equalto", function() {

	expect(12);
	
	$('#testinput').val('10');

	ok($.formvalidation($('#testinput').val(), {equalto: 'testinput'}).valid, "[string] '#testinput' is valid");
	ok($('<input type="text" value="1" />').val($('#testinput').val()).formvalidation({rules:{equalto: 'testinput'}}).formvalidation('isvalid'), "[input:options] '#testinput+1' is valid");
	ok($('<input type="text" value="1" equalto="testinput" />').val($('#testinput').val()).formvalidation().formvalidation('isvalid'), "[input:attribute] '#testinput' is valid");
	ok(!$.formvalidation('', {equalto: 'testinput'}).valid, "[string] '' is not valid");
	ok(!$('<input type="text" value="" />').formvalidation({rules:{equalto: 'testinput'}}).formvalidation('isvalid'), "[input:options] '' is not valid");
	ok(!$('<input type="text" value="" equalto="testinput" />').formvalidation().formvalidation('isvalid'), "[input:attribute] '' is not valid");
	ok(!$.formvalidation(1, {equalto: 'testinput'}).valid, "[string] '1' is not valid");
	ok(!$('<input type="text" value="1" />').formvalidation({rules:{equalto: 'testinput'}}).formvalidation('isvalid'), "[input:options] '1' is not valid");
	ok(!$('<input type="text" value="1" equalto="testinput" />').formvalidation().formvalidation('isvalid'), "[input:attribute] '1' is not valid");
	ok(!$.formvalidation(999, {equalto: 'testinput'}).valid, "[string] '999' is not valid");
	ok(!$('<input type="text" value="999" />').formvalidation({rules:{equalto: 'testinput'}}).formvalidation('isvalid'), "[input:options] '999' is not valid");
	ok(!$('<input type="text" value="999" equalto="testinput" />').formvalidation().formvalidation('isvalid'), "[input:attribute] '999' is not valid");
	
});


})(jQuery);
